﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SqlServerDriver
{
	public partial class DatabaseSelectionForm : Form
	{

		public DatabaseSelectionForm(List<String>databaseNames, String currentName)
		{
			InitializeComponent();
			
			foreach (String databaseName in databaseNames)
			{
				this.listDatabases.Items.Add(databaseName);
			}
			this.SelectedDatabase = currentName;
			this.listDatabases.SelectedIndex = listDatabases.Items.IndexOf(currentName);
			if (this.listDatabases.SelectedIndex == -1)
				this.listDatabases.SelectedIndex = 0;
		}
		
		public String SelectedDatabase {get; set; }

		private void BtnOk_Click(object sender, EventArgs e)
		{
			this.SelectedDatabase = listDatabases.Items[listDatabases.SelectedIndex].ToString();
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void BtnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}

		private void ListDatabases_DoubleClick(object sender, EventArgs e)
		{
			this.BtnOk_Click(sender, e);
		}
	}
}
